<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="auth" uri="http://www.recharge.com/authority" %>
<auth:authority role="0" />
<%--
这边要注意一个easyui 的问题，当panel tabs 这种href 引用页面
页面中不能有html body head 因为他只会把body 里面的内容 append 到页面中
--%>
<div id="dataCondition" class="easyui-panel"
     style="width:1095px;height:150px;padding:10px;background:#fafafa;"
     data-options="closable:false,
                collapsible:false,minimizable:false,maximizable:false">
    <form id="sup-mainForm" method="post">

        <table>
            <tr>
                <td><label for="supplierId">供货商编号:</label></td>
                <td><input class="easyui-validatebox" type="text" name="supplierId" id="supplierId"/></td>
                <td><label for="supplierName">供货商名称:</label></td>
                <td><input class="easyui-validatebox" type="text" name="supplierName" id="supplierName"/></td>
            </tr>

            <tr>
                <td colspan="3"></td>
                <td><input type="button" id="submit_sup-mainForm" value="查询" onclick="submitSupMainForm();">
                </td>
            </tr>
        </table>
    </form>
</div>


<div id="dataView" class="easyui-panel" title="查询结果"
     style="width:1095px;background:#fafafa; height: 415px;overflow-y:hidden"
     data-options="closable:false,
                collapsible:false,minimizable:false,maximizable:false">
    <table id="select-sup-dg">
    </table>
</div>

<div id="select-sup-detailDialog"></div>

<script language="JavaScript" type="text/javascript">

    $().ready(function () {

        //初始化查询结果表格
        $('#select-sup-dg').datagrid({
            columns:[[
                {field:'supplierId',title:'供货商编号',width:100},
                {field:'supplierName',title:'供货商名称',width:150},
                {field:'supplierStatus',title:'供货商状态',align:'center',width:100,formatter: function(value,row,index){
                    if(value==true){
                        return '<a href="#" onclick="updateInfo('+row.supplierId+',false);return false;"><font color="#7fff00">打开</font></a>';
                    }else{
                        return '<a href="#" onclick="updateInfo('+row.supplierId+',true);return false;"><font color="#dc143c">关闭</font></a>';
                    }
                }}
            ]],
            pagination: true,
            height: 390,
            singleSelect : true,
            toolbar: [{
                iconCls: 'icon-add',
                text : "选择供货商",
                handler: function(){
                    var selectSupSelection = $('#select-sup-dg').datagrid("getSelected");
                    if(selectSupSelection==null || selectSupSelection.length==0){
//                        alert(JSON.stringify(selectProductSelections));
                        $.messager.alert('Warn','没有选择供货商');
                        return ;
                    }

                    var proSups = [];

                    for(var i=0; i<selectProductSelections.length;i++ ){
                        var proSup = {};
                        proSup.productId = selectProductSelections[i].productId;
                        proSup.productName = selectProductSelections[i].productName;
                        proSup.supId = selectSupSelection.supplierId;
                        proSup.supName = selectSupSelection.supplierName;
                        proSup.weight = 1;
                        proSup.priority =1;
                        proSup.status=false;
                        proSups.push(proSup);
                    }

                    $.post("productSup/addInfo", {"context":JSON.stringify(proSups)},function(responseInfo){

                        $.messager.alert('Info','添加成功');
                    });

                }
            }]
        });

        var pager = $('#select-sup-dg').datagrid().datagrid('getPager');
        pager.pagination({
            onBeforeRefresh:function(pageNumber, pageSize){
                getListData(pageNumber,pageSize);
            },
            onSelectPage:function(pageNumber, pageSize){
                getListData(pageNumber,pageSize);
            }
        });


    });

    function getListData(pageNumber, pageSize){
        var param = $("#sup-mainForm").serializeArray();
        param.push({name:"curr",value:pageNumber});
        param.push({name:"pageSize",value:pageSize});

        $.post("supplier/queryList", param,function(responseInfo){
            $('#select-sup-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });

    }

    function updateInfo(supplierId,supplierStatus){
        var param = [];
        param.push({name:"supplierId",value:supplierId});
        param.push({name:"supplierStatus",value:supplierStatus});
        $.post("supplier/updateInfo", param,function(responseInfo){
        });
    }

    function submitSupMainForm() {
        var param = $("#sup-mainForm").serializeArray();
        param.push({name:"curr",value:1});
        param.push({name:"pageSize",value:10});

        $.post("supplier/queryList", param,function(responseInfo){
            $('#select-sup-dg').datagrid('loadData', {
                "total":responseInfo.count,
                "rows":responseInfo.data
            });
        });
    }
</script>